/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Example_10_Enum.java]
 * Creation Date        [20-Jun-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_oop;

/**
 * 
 * 枚举
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Example_10_Enum {

	/**
	 * 测试方法
	 * 
	 * @param args
	 *            命令行参数
	 */
	public static void main(String[] args) {
		// values方法返回所有枚举的值
		System.out.println("枚举值的数目: " + Size.values().length);

		// 遍历枚举类型的所有值
		Size[] sizes = Size.values();
		for (Size size : sizes) {
			System.out.print(size + " ");
		}
		System.out.println();

		Size size = Size.SMALL;
		// 枚举值的比较使用 ==, 而不使用equals()
		if (size == Size.SMALL) {
			System.out.println("sizes' values are equal.");
		}

		// 使用valueOf方法将字符串转换为枚举值
		String str = "MEDIUM";
		size = Size.valueOf(str);
		size = Enum.valueOf(Size.class, str);
		System.out.println(size);

		// 使用ordinal方法获得枚举值在枚举类型中声明的顺序
		System.out.println("SMALL的序号:" + Size.SMALL.ordinal());
		System.out.println("MEDIUM的序号:" + Size.MEDIUM.ordinal());
		System.out.println("LARGE的序号:" + Size.LARGE.ordinal());
		System.out.println("EXTRA_LARGE的序号:" + Size.EXTRA_LARGE.ordinal());
		System.out.println();

		SizeComplex small = SizeComplex.SMALL;
		System.out.println(small);
		SizeComplex large = SizeComplex.LARGE;
		System.out.println(large);

		// 枚举在switch语句中的运用
		switch (small) {
		case SMALL:
			System.out.println("小号");
			break;
		case MEDIUM:
			System.out.println("中号");
			break;
		case LARGE:
			System.out.println("大号");
			break;
		case EXTRA_LARGE:
			System.out.println("超大号");
			break;
		default:
			System.out.println("无号");
		}
	}

}
